import Vue from "vue";
import VueRouter from "vue-router";

if (process.env.NODE_ENV === "development") {
    Vue.use(VueRouter);
}

import { ROUTER_MODE } from "../config/app";

import Home from "../views/home/index.vue";

// 管理组相关
import adminRouter from "../views/userManage/admin/router.vue";
import authAdmin from "../views/userManage/admin/authAdmin.vue";
import authRole from "../views/userManage/admin/authRole.vue";
import authPermissionRule from "../views/userManage/admin/authPermissionRule.vue";

//立即下单
import inspection from "../views/order/inspection.vue";
import loading from "../views/order/loading.vue";
//订单管理
import orderList from "../views/orderManage/orderList.vue";
//报告管理
import reportList from "../views/reportManage/reportList.vue";
//资金管理
import wallet from "../views/moneyManage/wallet.vue";
// 账户管理
import personalInformation from "../views/account/personalInformation.vue";


// Vue.use(VueRouter);

const err401 = r =>
    require.ensure([], () => r(require("../views/error/err401.vue")), "home");
const err404 = r =>
    require.ensure([], () => r(require("../views/error/err404.vue")), "home");
const login = r =>
    require.ensure([], () => r(require("../views/login/index.vue")), "home");
const index = r =>
    require.ensure([], () => r(require("../views/index/IndexPage.vue")), "home");


// 注意 权限字段 authRule （严格区分大小写）
export const constantRouterMap = [
    {
        path: "*",
        component: err404,
        hidden: true
    },
    {
        path: "/401",
        component: err401,
        name: "401",
        hidden: true
    },
    {
        path: "/404",
        component: err404,
        name: "404",
        hidden: true
    },
    {
        path: "/500",
        component: err404,
        name: "500",
        hidden: true
    },
    {
        path: "/login",
        component: login,
        name: "登录",
        hidden: true
    },
    {
        path: "/",
        component: Home,
        redirect: "/index",
        name: "首页",
        hidden: true
    },
    {
        path: "/index",
        component: Home,
        redirect: "/index",
        icon: "shouye",
        name: "首页",
        noDropdown: true,
        children: [
            {
                path: "",
                component: index
            }
        ]
    }
];

export default new VueRouter({
    // mode: 'history', //后端支持可开
    mode: ROUTER_MODE,
    routes: constantRouterMap,
    strict: process.env.NODE_ENV !== "production"
});

export const asyncRouterMap = [
    {
        path: "/order",
        component: Home,
        icon: "guanggao",
        name: "立即下单",
        meta: {
            // authRule: ["ad_manage"]
        },
        // noDropdown: true,
        children: [
            {
                path: "inspection",
                component: inspection,
                name: "验货",
                icon: "",
                meta: {
                    // authRule: ["admin/ad/site/index"]
                }
            },
            {
                path: "loading",
                component: loading,
                name: "监装",
                icon: "",
                meta: {
                    // authRule: ["admin/ad/ad/index"]
                }
            }
        ]
    },
    {
        path: "/orderManage",
        component: Home,
        icon: "guanggao",
        name: "订单管理",
        meta: {
            // authRule: ["ad_manage"]
        },
        // noDropdown: true,
        children: [
            {
                path: "orderList",
                component: orderList,
                name: "验货订单",
                icon: "",
                meta: {
                    // authRule: ["admin/ad/site/index"]
                }
            }
        ]
    },
    {
        path: "/recordManage",
        component: Home,
        icon: "guanggao",
        name: "报告管理",
        meta: {
            // authRule: ["ad_manage"]
        },
        noDropdown: true,
        children: [
            {
                path: "",
                component: reportList,
                name: "报告管理",
                icon: "",
                meta: {
                    // authRule: ["admin/ad/site/index"]
                }
            }
        ]
    },
    {
        path: "/moneyManage",
        component: Home,
        icon: "guanggao",
        name: "资金管理",
        meta: {
            // authRule: ["ad_manage"]
        },
        // noDropdown: true,
        children: [
            {
                path: "wallet",
                component: wallet,
                name: "钱包账户",
                icon: "",
                meta: {
                    // authRule: ["admin/ad/site/index"]
                }
            }
        ]
    },
    {
        path: "/account",
        redirect: "/account/personalInformation",
        component: Home,
        icon: "guanggao",
        name: "账户管理",
        meta: {
            // authRule: ["ad_manage"]
        },
        // noDropdown: true,
        children: [
            {
                path: "personalInformation",
                component: personalInformation,
                name: "个人信息",
                icon: "",
                meta: {
                    // authRule: ["admin/ad/site/index"]
                }
            }
        ]
    },
];
